package org.iridium.swinggtalk.tools;

/**
 *
 * @author iridiumcao
 */
public class MessageTools {

    /**
     * like this:
     * <message id="38" to="iridium.dev.0001@gmail.com/Smack" from="iridium.dev.0003@gmail.com/Talk.v1043C9102EB" type="chat">
     *      <body>hELLO, tHIS IS THE MESSAGE TO BE EXTRACTED!</body>
     *      <thread>dvuVl0</thread>
     *      <active xmlns="http://jabber.org/protocol/chatstates" />
     *      <x xmlns="google:nosave"></x>
     *      <record xmlns="http://jabber.org/protocol/archive"></record>
     * </message>
     * @param orginalXml
     * @return
     */
    public static String extractMessage(String originalXml) {
//        String messageBody = null;
//        XPathFactory factory = XPathFactory.newInstance();
//        XPath xpath = factory.newXPath();
//        try {
//            messageBody = xpath.evaluate("//message/body[1]/", originalXml);
//        } catch (XPathExpressionException ex) {
//            Logger.getLogger(MessageTools.class.getName()).log(Level.SEVERE, null, ex);
//        }
        return originalXml.substring(originalXml.indexOf("<body>") + 6, originalXml.indexOf("</body>"));
    }
}
